package org.crh.appointment.impl;

import org.crh.appointment.AppointmentRecordService;
import org.crh.appointment.domain.AppointmentReq;
import org.crh.appointment.mapper.AppointmentRecordMapper;
import org.crh.common.domain.AppointmentRecord;
import org.crh.common.util.SnowflakeOrderIdGenerator;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


/**
 * @description:
 * @author: RenHai Chen
 * @date: 2025/4/3 13:44
 */
@Service
public class AppointmentRecordServiceImpl implements AppointmentRecordService {
    @Resource
    private AppointmentRecordMapper appointmentRecordMapper;

    @Override
    public AppointmentRecord getRecord(String recordNo) {
        AppointmentRecord order = appointmentRecordMapper.getRecord(recordNo);

        return order;
    }

    @Override
    public AppointmentRecord createAppointmentRecord(AppointmentReq appointmentReq) {
        AppointmentRecord appointmentRecord = new AppointmentRecord();
        // 初始化生成器（假设数据中心ID=1，机器ID=1）
        SnowflakeOrderIdGenerator generator = new SnowflakeOrderIdGenerator(1L, 1L);
        // 生成订单号
        String appointmentRecordId = generator.generateOrderId();
        appointmentRecord.setAppointmentId(appointmentRecordId);
        appointmentRecord.setUserId(appointmentReq.getUserId());
        appointmentRecord.setSlotId(appointmentReq.getSlotId());
        appointmentRecord.setPhone(appointmentReq.getPhone());
        appointmentRecord.setExpireTime(appointmentReq.getExpireTime());
        appointmentRecordMapper.createAppointmentRecord(appointmentRecord);

        return appointmentRecord;
    }

    @Override
    public int updateStatus(AppointmentRecord appointmentRecord) {
        return appointmentRecordMapper.updateStatus(appointmentRecord);
    }
}
